<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE ConstraintKinds #-}</span><span>
</span><span id="line-3"></span><span class="hs-pragma">{-# LANGUAGE DeriveFunctor #-}</span><span>
</span><span id="line-4"></span><span class="hs-pragma">{-# LANGUAGE KindSignatures #-}</span><span>
</span><span id="line-5"></span><span class="hs-pragma">{-# LANGUAGE FlexibleContexts #-}</span><span>
</span><span id="line-6"></span><span>
</span><span id="line-7"></span><span class="hs-comment">{-
(c) The University of Glasgow 2006
(c) The GRASP/AQUA Project, Glasgow University, 1992-1998
-}</span><span>
</span><span id="line-11"></span><span>
</span><span id="line-12"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Data.Maybe</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-13"></span><span>        </span><span class="hs-keyword">module</span><span> </span><span class="annot"><a href="../../base/src/Data.Maybe.html#"><span class="hs-identifier">Data.Maybe</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-14"></span><span>
</span><span id="line-15"></span><span>        </span><span class="annot"><a href="GHC.Data.Maybe.html#MaybeErr"><span class="hs-identifier">MaybeErr</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-comment">-- Instance of Monad</span><span>
</span><span id="line-16"></span><span>        </span><span class="annot"><a href="GHC.Data.Maybe.html#failME"><span class="hs-identifier">failME</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Maybe.html#isSuccess"><span class="hs-identifier">isSuccess</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-17"></span><span>
</span><span id="line-18"></span><span>        </span><span class="annot"><a href="GHC.Data.Maybe.html#orElse"><span class="hs-identifier">orElse</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-19"></span><span>        </span><span class="annot"><a href="GHC.Data.Maybe.html#firstJust"><span class="hs-identifier">firstJust</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Maybe.html#firstJusts"><span class="hs-identifier">firstJusts</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-20"></span><span>        </span><span class="annot"><a href="GHC.Data.Maybe.html#whenIsJust"><span class="hs-identifier">whenIsJust</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-21"></span><span>        </span><span class="annot"><a href="GHC.Data.Maybe.html#expectJust"><span class="hs-identifier">expectJust</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-22"></span><span>        </span><span class="annot"><a href="GHC.Data.Maybe.html#rightToMaybe"><span class="hs-identifier">rightToMaybe</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-23"></span><span>
</span><span id="line-24"></span><span>        </span><span class="annot"><span class="hs-comment">-- * MaybeT</span></span><span>
</span><span id="line-25"></span><span>        </span><span class="annot"><a href="../../transformers/src/Control.Monad.Trans.Maybe.html#MaybeT"><span class="hs-identifier">MaybeT</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Maybe.html#liftMaybeT"><span class="hs-identifier">liftMaybeT</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Maybe.html#tryMaybeT"><span class="hs-identifier">tryMaybeT</span></a></span><span>
</span><span id="line-26"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-27"></span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-29"></span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Monad.html#"><span class="hs-identifier">Control.Monad</span></a></span><span>
</span><span id="line-31"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../transformers/src/Control.Monad.Trans.Maybe.html#"><span class="hs-identifier">Control.Monad.Trans.Maybe</span></a></span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Exception.html#"><span class="hs-identifier">Control.Exception</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.IO.html#catch"><span class="hs-identifier">catch</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Exception.Type.html#SomeException"><span class="hs-identifier">SomeException</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Maybe.html#"><span class="hs-identifier">Data.Maybe</span></a></span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Misc.html"><span class="hs-identifier">GHC.Utils.Misc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Stack.Types.html#HasCallStack"><span class="hs-identifier">HasCallStack</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-35"></span><span>
</span><span id="line-36"></span><span class="hs-keyword">infixr</span><span> </span><span class="hs-number">4</span><span> </span><span class="annot"><a href="GHC.Data.Maybe.html#orElse"><span class="hs-operator hs-type">`orElse`</span></a></span><span>
</span><span id="line-37"></span><span>
</span><span id="line-38"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
\subsection[Maybe type]{The @Maybe@ type}
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-45"></span><span>
</span><span id="line-46"></span><span id="local-6989586621680780793"><span class="annot"><a href="GHC.Data.Maybe.html#firstJust"><span class="hs-identifier hs-type">firstJust</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780793"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780793"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780793"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-47"></span><span id="firstJust"><span class="annot"><span class="annottext">firstJust :: forall a. Maybe a -&gt; Maybe a -&gt; Maybe a
</span><a href="GHC.Data.Maybe.html#firstJust"><span class="hs-identifier hs-var hs-var">firstJust</span></a></span></span><span> </span><span id="local-6989586621680780683"><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621680780683"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span id="local-6989586621680780682"><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621680780682"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Maybe a] -&gt; Maybe a
forall a. [Maybe a] -&gt; Maybe a
</span><a href="GHC.Data.Maybe.html#firstJusts"><span class="hs-identifier hs-var">firstJusts</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621680780683"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621680780682"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-48"></span><span>
</span><span id="line-49"></span><span class="hs-comment">-- | Takes a list of @Maybes@ and returns the first @Just@ if there is one, or</span><span>
</span><span id="line-50"></span><span class="hs-comment">-- @Nothing@ otherwise.</span><span>
</span><span id="line-51"></span><span id="local-6989586621680780791"><span class="annot"><a href="GHC.Data.Maybe.html#firstJusts"><span class="hs-identifier hs-type">firstJusts</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780791"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780791"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-52"></span><span id="firstJusts"><span class="annot"><span class="annottext">firstJusts :: forall a. [Maybe a] -&gt; Maybe a
</span><a href="GHC.Data.Maybe.html#firstJusts"><span class="hs-identifier hs-var hs-var">firstJusts</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Maybe a] -&gt; Maybe a
forall (t :: * -&gt; *) (m :: * -&gt; *) a.
(Foldable t, MonadPlus m) =&gt;
t (m a) -&gt; m a
</span><a href="../../base/src/Data.Foldable.html#msum"><span class="hs-identifier hs-var">msum</span></a></span><span>
</span><span id="line-53"></span><span>
</span><span id="line-54"></span><span id="local-6989586621680780784"><span class="annot"><a href="GHC.Data.Maybe.html#expectJust"><span class="hs-identifier hs-type">expectJust</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Stack.Types.html#HasCallStack"><span class="hs-identifier hs-type">HasCallStack</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780784"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680780784"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-55"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.Data.Maybe.html#expectJust"><span class="hs-pragma hs-type">expectJust</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-56"></span><span id="expectJust"><span class="annot"><span class="annottext">expectJust :: forall a. HasCallStack =&gt; String -&gt; Maybe a -&gt; a
</span><a href="GHC.Data.Maybe.html#expectJust"><span class="hs-identifier hs-var hs-var">expectJust</span></a></span></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-identifier">_</span></span><span>   </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680780673"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680780673"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680780673"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-57"></span><span class="annot"><a href="GHC.Data.Maybe.html#expectJust"><span class="hs-identifier hs-var">expectJust</span></a></span><span> </span><span id="local-6989586621680780672"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680780672"><span class="hs-identifier hs-var">err</span></a></span></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; a
forall a. HasCallStack =&gt; String -&gt; a
</span><a href="../../base/src/GHC.Err.html#error"><span class="hs-identifier hs-var">error</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;expectJust &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680780672"><span class="hs-identifier hs-var">err</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-58"></span><span>
</span><span id="line-59"></span><span id="local-6989586621680780778"><span id="local-6989586621680780779"><span class="annot"><a href="GHC.Data.Maybe.html#whenIsJust"><span class="hs-identifier hs-type">whenIsJust</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780779"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780778"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680780778"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680780779"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680780779"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span></span><span>
</span><span id="line-60"></span><span id="whenIsJust"><span class="annot"><span class="annottext">whenIsJust :: forall (m :: * -&gt; *) a. Monad m =&gt; Maybe a -&gt; (a -&gt; m ()) -&gt; m ()
</span><a href="GHC.Data.Maybe.html#whenIsJust"><span class="hs-identifier hs-var hs-var">whenIsJust</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680780668"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680780668"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680780667"><span class="annot"><span class="annottext">a -&gt; m ()
</span><a href="#local-6989586621680780667"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; m ()
</span><a href="#local-6989586621680780667"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680780668"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-61"></span><span class="annot"><a href="GHC.Data.Maybe.html#whenIsJust"><span class="hs-identifier hs-var">whenIsJust</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>  </span><span class="annot"><span class="annottext">a -&gt; m ()
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; m ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-62"></span><span>
</span><span id="line-63"></span><span class="hs-comment">-- | Flipped version of @fromMaybe@, useful for chaining.</span><span>
</span><span id="line-64"></span><span id="local-6989586621680780773"><span class="annot"><a href="GHC.Data.Maybe.html#orElse"><span class="hs-identifier hs-type">orElse</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780773"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680780773"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680780773"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-65"></span><span id="orElse"><span class="annot"><span class="annottext">orElse :: forall a. Maybe a -&gt; a -&gt; a
</span><a href="GHC.Data.Maybe.html#orElse"><span class="hs-identifier hs-var hs-var">orElse</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(a -&gt; Maybe a -&gt; a) -&gt; Maybe a -&gt; a -&gt; a
forall a b c. (a -&gt; b -&gt; c) -&gt; b -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#flip"><span class="hs-identifier hs-var">flip</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; Maybe a -&gt; a
forall a. a -&gt; Maybe a -&gt; a
</span><a href="../../base/src/Data.Maybe.html#fromMaybe"><span class="hs-identifier hs-var">fromMaybe</span></a></span><span>
</span><span id="line-66"></span><span>
</span><span id="line-67"></span><span id="local-6989586621680780766"><span id="local-6989586621680780767"><span class="annot"><a href="GHC.Data.Maybe.html#rightToMaybe"><span class="hs-identifier hs-type">rightToMaybe</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780767"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780766"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780766"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-68"></span><span id="rightToMaybe"><span class="annot"><span class="annottext">rightToMaybe :: forall a b. Either a b -&gt; Maybe b
</span><a href="GHC.Data.Maybe.html#rightToMaybe"><span class="hs-identifier hs-var hs-var">rightToMaybe</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe b
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-69"></span><span class="annot"><a href="GHC.Data.Maybe.html#rightToMaybe"><span class="hs-identifier hs-var">rightToMaybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span id="local-6989586621680780664"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680780664"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">b -&gt; Maybe b
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680780664"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-70"></span><span>
</span><span id="line-71"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
\subsection[MaybeT type]{The @MaybeT@ monad transformer}
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-78"></span><span>
</span><span id="line-79"></span><span class="hs-comment">-- We had our own MaybeT in the past. Now we reuse transformer's MaybeT</span><span>
</span><span id="line-80"></span><span>
</span><span id="line-81"></span><span id="local-6989586621680780761"><span id="local-6989586621680780762"><span class="annot"><a href="GHC.Data.Maybe.html#liftMaybeT"><span class="hs-identifier hs-type">liftMaybeT</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780762"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680780762"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780761"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../transformers/src/Control.Monad.Trans.Maybe.html#MaybeT"><span class="hs-identifier hs-type">MaybeT</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780762"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780761"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-82"></span><span id="liftMaybeT"><span class="annot"><span class="annottext">liftMaybeT :: forall (m :: * -&gt; *) a. Monad m =&gt; m a -&gt; MaybeT m a
</span><a href="GHC.Data.Maybe.html#liftMaybeT"><span class="hs-identifier hs-var hs-var">liftMaybeT</span></a></span></span><span> </span><span id="local-6989586621680780661"><span class="annot"><span class="annottext">m a
</span><a href="#local-6989586621680780661"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">m (Maybe a) -&gt; MaybeT m a
forall (m :: * -&gt; *) a. m (Maybe a) -&gt; MaybeT m a
</span><a href="../../transformers/src/Control.Monad.Trans.Maybe.html#MaybeT"><span class="hs-identifier hs-var">MaybeT</span></a></span><span> </span><span class="annot"><span class="annottext">(m (Maybe a) -&gt; MaybeT m a) -&gt; m (Maybe a) -&gt; MaybeT m a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; Maybe a
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">(a -&gt; Maybe a) -&gt; m a -&gt; m (Maybe a)
forall (m :: * -&gt; *) a1 r. Monad m =&gt; (a1 -&gt; r) -&gt; m a1 -&gt; m r
</span><a href="../../base/src/GHC.Base.html#liftM"><span class="hs-operator hs-var">`liftM`</span></a></span><span> </span><span class="annot"><span class="annottext">m a
</span><a href="#local-6989586621680780661"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-83"></span><span>
</span><span id="line-84"></span><span class="hs-comment">-- | Try performing an 'IO' action, failing on error.</span><span>
</span><span id="line-85"></span><span id="local-6989586621680780749"><span class="annot"><a href="GHC.Data.Maybe.html#tryMaybeT"><span class="hs-identifier hs-type">tryMaybeT</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621680780749"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../transformers/src/Control.Monad.Trans.Maybe.html#MaybeT"><span class="hs-identifier hs-type">MaybeT</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621680780749"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-86"></span><span id="tryMaybeT"><span class="annot"><span class="annottext">tryMaybeT :: forall a. IO a -&gt; MaybeT IO a
</span><a href="GHC.Data.Maybe.html#tryMaybeT"><span class="hs-identifier hs-var hs-var">tryMaybeT</span></a></span></span><span> </span><span id="local-6989586621680780652"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621680780652"><span class="hs-identifier hs-var">action</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO (Maybe a) -&gt; MaybeT IO a
forall (m :: * -&gt; *) a. m (Maybe a) -&gt; MaybeT m a
</span><a href="../../transformers/src/Control.Monad.Trans.Maybe.html#MaybeT"><span class="hs-identifier hs-var">MaybeT</span></a></span><span> </span><span class="annot"><span class="annottext">(IO (Maybe a) -&gt; MaybeT IO a) -&gt; IO (Maybe a) -&gt; MaybeT IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">IO (Maybe a) -&gt; (SomeException -&gt; IO (Maybe a)) -&gt; IO (Maybe a)
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="../../base/src/GHC.IO.html#catch"><span class="hs-identifier hs-var">catch</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Maybe a
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">(a -&gt; Maybe a) -&gt; IO a -&gt; IO (Maybe a)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-operator hs-var">`fmap`</span></a></span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621680780652"><span class="hs-identifier hs-var">action</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; IO (Maybe a)
forall {m :: * -&gt; *} {a}. Monad m =&gt; SomeException -&gt; m (Maybe a)
</span><a href="#local-6989586621680780651"><span class="hs-identifier hs-var">handler</span></a></span><span>
</span><span id="line-87"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-88"></span><span>    </span><span id="local-6989586621680780651"><span class="annot"><span class="annottext">handler :: SomeException -&gt; m (Maybe a)
</span><a href="#local-6989586621680780651"><span class="hs-identifier hs-var hs-var">handler</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span> </span><span class="annot"><span class="annottext">e
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; m (Maybe a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-89"></span><span>
</span><span id="line-90"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
\subsection[MaybeErr type]{The @MaybeErr@ type}
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-97"></span><span>
</span><span id="line-98"></span><span class="hs-keyword">data</span><span> </span><span id="MaybeErr"><span class="annot"><a href="GHC.Data.Maybe.html#MaybeErr"><span class="hs-identifier hs-var">MaybeErr</span></a></span></span><span> </span><span id="local-6989586621680780734"><span class="annot"><a href="#local-6989586621680780734"><span class="hs-identifier hs-type">err</span></a></span></span><span> </span><span id="local-6989586621680780708"><span class="annot"><a href="#local-6989586621680780708"><span class="hs-identifier hs-type">val</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="Succeeded"><span class="annot"><a href="GHC.Data.Maybe.html#Succeeded"><span class="hs-identifier hs-var">Succeeded</span></a></span></span><span> </span><span class="annot"><a href="#local-6989586621680780708"><span class="hs-identifier hs-type">val</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span id="Failed"><span class="annot"><a href="GHC.Data.Maybe.html#Failed"><span class="hs-identifier hs-var">Failed</span></a></span></span><span> </span><span class="annot"><a href="#local-6989586621680780734"><span class="hs-identifier hs-type">err</span></a></span><span>
</span><span id="line-99"></span><span>    </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680780641"><span id="local-6989586621680780643"><span class="annot"><span class="annottext">(forall a b. (a -&gt; b) -&gt; MaybeErr err a -&gt; MaybeErr err b)
-&gt; (forall a b. a -&gt; MaybeErr err b -&gt; MaybeErr err a)
-&gt; Functor (MaybeErr err)
forall a b. a -&gt; MaybeErr err b -&gt; MaybeErr err a
forall a b. (a -&gt; b) -&gt; MaybeErr err a -&gt; MaybeErr err b
forall err a b. a -&gt; MaybeErr err b -&gt; MaybeErr err a
forall err a b. (a -&gt; b) -&gt; MaybeErr err a -&gt; MaybeErr err b
forall (f :: * -&gt; *).
(forall a b. (a -&gt; b) -&gt; f a -&gt; f b)
-&gt; (forall a b. a -&gt; f b -&gt; f a) -&gt; Functor f
&lt;$ :: forall a b. a -&gt; MaybeErr err b -&gt; MaybeErr err a
$c&lt;$ :: forall err a b. a -&gt; MaybeErr err b -&gt; MaybeErr err a
fmap :: forall a b. (a -&gt; b) -&gt; MaybeErr err a -&gt; MaybeErr err b
$cfmap :: forall err a b. (a -&gt; b) -&gt; MaybeErr err a -&gt; MaybeErr err b
</span><a href="../../base/src/GHC.Base.html#Functor"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var">Functor</span></a></span></span></span><span class="hs-special">)</span><span>
</span><span id="line-100"></span><span>
</span><span id="line-101"></span><span id="local-6989586621680780722"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680780629"><span id="local-6989586621680780631"><span id="local-6989586621680780633"><span class="annot"><a href="../../base/src/GHC.Base.html#Applicative"><span class="hs-identifier hs-type">Applicative</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Data.Maybe.html#MaybeErr"><span class="hs-identifier hs-type">MaybeErr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780722"><span class="hs-identifier hs-type">err</span></a></span><span class="hs-special">)</span></span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-102"></span><span>  </span><span id="local-6989586621680780627"><span class="annot"><span class="annottext">pure :: forall a. a -&gt; MaybeErr err a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var hs-var hs-var hs-var">pure</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; MaybeErr err a
forall err a. a -&gt; MaybeErr err a
</span><a href="GHC.Data.Maybe.html#Succeeded"><span class="hs-identifier hs-var">Succeeded</span></a></span><span>
</span><span id="line-103"></span><span>  </span><span id="local-6989586621680780625"><span class="annot"><span class="annottext">&lt;*&gt; :: forall a b.
MaybeErr err (a -&gt; b) -&gt; MaybeErr err a -&gt; MaybeErr err b
</span><a href="../../base/src/GHC.Base.html#%3C%2A%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">(&lt;*&gt;)</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">MaybeErr err (a -&gt; b) -&gt; MaybeErr err a -&gt; MaybeErr err b
forall (m :: * -&gt; *) a b. Monad m =&gt; m (a -&gt; b) -&gt; m a -&gt; m b
</span><a href="../../base/src/GHC.Base.html#ap"><span class="hs-identifier hs-var">ap</span></a></span></span><span>
</span><span id="line-104"></span><span>
</span><span id="line-105"></span><span id="local-6989586621680780720"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680780617"><span id="local-6989586621680780619"><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Data.Maybe.html#MaybeErr"><span class="hs-identifier hs-type">MaybeErr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780720"><span class="hs-identifier hs-type">err</span></a></span><span class="hs-special">)</span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-106"></span><span>  </span><span class="annot"><a href="GHC.Data.Maybe.html#Succeeded"><span class="hs-identifier hs-type">Succeeded</span></a></span><span> </span><span id="local-6989586621680780615"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680780615"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span id="local-6989586621680780614"><span class="annot"><span class="annottext">&gt;&gt;= :: forall a b.
MaybeErr err a -&gt; (a -&gt; MaybeErr err b) -&gt; MaybeErr err b
</span><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var hs-var hs-var hs-var">&gt;&gt;=</span></a></span></span><span> </span><span id="local-6989586621680780613"><span class="annot"><span class="annottext">a -&gt; MaybeErr err b
</span><a href="#local-6989586621680780613"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; MaybeErr err b
</span><a href="#local-6989586621680780613"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680780615"><span class="hs-identifier hs-var">v</span></a></span><span>
</span><span id="line-107"></span><span>  </span><span class="annot"><a href="GHC.Data.Maybe.html#Failed"><span class="hs-identifier hs-type">Failed</span></a></span><span> </span><span id="local-6989586621680780612"><span class="annot"><span class="annottext">err
</span><a href="#local-6989586621680780612"><span class="hs-identifier hs-var">e</span></a></span></span><span>    </span><span class="annot"><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; MaybeErr err b
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">err -&gt; MaybeErr err b
forall err val. err -&gt; MaybeErr err val
</span><a href="GHC.Data.Maybe.html#Failed"><span class="hs-identifier hs-var">Failed</span></a></span><span> </span><span class="annot"><span class="annottext">err
</span><a href="#local-6989586621680780612"><span class="hs-identifier hs-var">e</span></a></span></span><span>
</span><span id="line-108"></span><span>
</span><span id="line-109"></span><span id="local-6989586621680780706"><span id="local-6989586621680780707"><span class="annot"><a href="GHC.Data.Maybe.html#isSuccess"><span class="hs-identifier hs-type">isSuccess</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Data.Maybe.html#MaybeErr"><span class="hs-identifier hs-type">MaybeErr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780707"><span class="hs-identifier hs-type">err</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780706"><span class="hs-identifier hs-type">val</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span></span></span><span>
</span><span id="line-110"></span><span id="isSuccess"><span class="annot"><span class="annottext">isSuccess :: forall err val. MaybeErr err val -&gt; Bool
</span><a href="GHC.Data.Maybe.html#isSuccess"><span class="hs-identifier hs-var hs-var">isSuccess</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Data.Maybe.html#Succeeded"><span class="hs-identifier hs-type">Succeeded</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-111"></span><span class="annot"><a href="GHC.Data.Maybe.html#isSuccess"><span class="hs-identifier hs-var">isSuccess</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Data.Maybe.html#Failed"><span class="hs-identifier hs-type">Failed</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-112"></span><span>
</span><span id="line-113"></span><span id="local-6989586621680780610"><span id="local-6989586621680780611"><span class="annot"><a href="GHC.Data.Maybe.html#failME"><span class="hs-identifier hs-type">failME</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621680780611"><span class="hs-identifier hs-type">err</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Maybe.html#MaybeErr"><span class="hs-identifier hs-type">MaybeErr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780611"><span class="hs-identifier hs-type">err</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680780610"><span class="hs-identifier hs-type">val</span></a></span></span></span><span>
</span><span id="line-114"></span><span id="failME"><span class="annot"><span class="annottext">failME :: forall err val. err -&gt; MaybeErr err val
</span><a href="GHC.Data.Maybe.html#failME"><span class="hs-identifier hs-var hs-var">failME</span></a></span></span><span> </span><span id="local-6989586621680780609"><span class="annot"><span class="annottext">err
</span><a href="#local-6989586621680780609"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">err -&gt; MaybeErr err val
forall err val. err -&gt; MaybeErr err val
</span><a href="GHC.Data.Maybe.html#Failed"><span class="hs-identifier hs-var">Failed</span></a></span><span> </span><span class="annot"><span class="annottext">err
</span><a href="#local-6989586621680780609"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-115"></span></pre></body></html>